﻿using System;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class FormIsValidateWorker
	{
		
		public static bool isValidate(Form form)
		{
			if (form.SchemaValiResult == JetConstant.DATAVALI_FALSE)
			{
				return false;
			}
			if (form.ErrCondValiModalMessage != null && form.ErrCondValiModalMessage.Length > 0)
			{
				return false;
			}
			if (form.FieldErrorList.Count > 0)
			{
				return false;
			}
			return true;
		}

        //0859 //2012.03.15 //Begin
        public static int Validate(Form form)
        {
            //CID 0925 //2011.05.30 //Begin
            FormBuildFieldListByXMLDocWorker.buildFieldListByXMLDoc(form, true);
            //CID 0925 //2011.05.30 //End
            form.IsDomReadonly = true;
            form.FieldErrorList.Clear();
            //CID 0778 //2011.03.28 //Begin
            FormRunSchemaValidationWorker.runSchemaValidation(form);
            FormRunErrorConditionWorker.runErrorCondition(form);
            //所有的OnValidate都只发送Updated操作,这样可以节省性能(减少一次调用),在InfoPath中是根据情况发送Delete和Insert.
            FormCodeDispatchWorker.OnValidate(form, FormCodeDispatchWorker.Updated);
            //CID 0778 //2011.03.28 //End
            int count = form.FieldErrorList.Count;
            form.FieldErrorList.Clear();
            form.IsDomReadonly = false;
            return count;
        }
        //0859 //2012.03.15 //End
	}
}